#include "stdafx.h"
#include "LGUIMultiMeter.h"
#include "LGUIContainer.h"

LGUIMultiMeter::LGUIMultiMeter(const TCHAR *_text, int id, int _x, int _y, int _h, int _numChoices, int _max) : LGUIWindow(_x,_y,_numChoices*BARSIZE,_h)
{
	text = _text;
	ID=id;
	max = _max;
	numChoices=_numChoices;
	values = new int[_numChoices];
	memset(values,0,sizeof(int)*_numChoices);
}

LGUIMultiMeter::~LGUIMultiMeter()
{
	delete [] values;
}

void LGUIMultiMeter::draw(int xoff, int yoff)
{
	if (isDirty)
	{
		buffer.rectFill(x+xoff,y+yoff,x+xoff+w,y+yoff+h,COLOR(0xFFFFFF));
		buffer.rect(x+xoff,y+yoff,x+xoff+w+1,y+yoff+h,COLOR(0x404040));
		for (int i=0; i<numChoices; i++)
		{
			int hh = values[i] * h / max;
			if (hh>h-2) hh=h-2;
			hh = h-2-hh;

			if (values[i] > 0)
			{
			buffer.rectFillDarkFaded(
				x+xoff+1+i*BARSIZE,
				y+yoff+1+hh,
				x+xoff+1+(i+1)*BARSIZE,
				1+y+yoff+h, values[i] > max ? COLOR(0xFF0000) : COLOR(0x90FF30));
			}
		}

		LRect dirty = *this;
		dirty.x += xoff;
		dirty.y += yoff;
		buffer.addDirtyRect(dirty);

		isDirty = false;
	}
}